package org.singledog.form.builder.dataset;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;

/**
 * @author adam
 * @date 2019/4/30
 */
public class DataSetRegistry {

	private static Map<DataSetType, DataSet> dataSetMap;

	static  {
		Map<DataSetType, DataSet> map = new HashMap<>();
		ServiceLoader<DataSet> serviceLoader = ServiceLoader.load(DataSet.class);
		for (DataSet dataSet : serviceLoader) {
			map.put(dataSet.supportDataSetType(), dataSet);
		}

		dataSetMap = Collections.unmodifiableMap(map);
	}

	public static DataSet queryDataSet(DataSetType dataSetType) {
		return dataSetMap.get(dataSetType);
	}

}
